package com.netty.bfport;

import com.netty.bfport.netty.server.NettyServer;
import com.netty.bfport.netty.websocket.WebSocketServer;
import com.netty.bfport.netty.websocket.WebSocketServerHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetSocketAddress;

@SpringBootApplication
@MapperScan("com.netty.bfport.mapper.*")
@EnableScheduling
@EnableAsync
public class BfPortApplication {

    static {
        System.setProperty("es.set.netty.runtime.available.processors","false");
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(BfPortApplication.class, args);
        NettyServer nettyServer = context.getBean(NettyServer.class);
        WebSocketServer webSocketServer = context.getBean(WebSocketServer.class);
        //启动服务端
//        NettyServer nettyServer = new NettyServer();
        try {
            nettyServer.start(new InetSocketAddress("0.0.0.0", 8090));
            WebSocketServerHandler.port=8100;
            webSocketServer.start(WebSocketServerHandler.port);
        }catch (Exception ex){
            System.err.println(ex);
        }
    }

}
